package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.entity.TbStudent;
import com.qf.entity.TbTeacher;
import com.qf.service.TbTeacherService;
import com.qf.mapper.TbTeacherMapper;
import com.qf.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 *
 */
@Service
public class TbTeacherServiceImpl extends ServiceImpl<TbTeacherMapper, TbTeacher>
    implements TbTeacherService{
     private final TbTeacherMapper tbTeacherMapper;

    public TbTeacherServiceImpl(TbTeacherMapper tbTeacherMapper) {
        this.tbTeacherMapper = tbTeacherMapper;
    }

    @Override
    public Result login(String snum,String password) {
        //1.严格的参数校验
        LambdaQueryWrapper<TbTeacher> lqw=new LambdaQueryWrapper<>();
        lqw.eq(TbTeacher::getJobnum,snum);
        TbTeacher tbTeacher = tbTeacherMapper.selectOne(lqw);


        String spassword = tbTeacher.getTpassword();



        return spassword.equals(password)?Result.success("登录成功"):Result.error("登录失败");
    }

    @Override
    public Result updatePassword(TbTeacher tbTeacher) {
        LambdaQueryWrapper<TbTeacher> lqw=new LambdaQueryWrapper<>();
        System.out.println(tbTeacher.getTemail());
        lqw.eq(TbTeacher::getTemail,tbTeacher.getTemail());
        TbTeacher selectTbTeacher = tbTeacherMapper.selectOne(lqw);
        System.out.println(selectTbTeacher);
        if(selectTbTeacher!=null){
            selectTbTeacher.setTpassword(tbTeacher.getTpassword());
            tbTeacherMapper.update(selectTbTeacher,lqw);
            return Result.success("更新成功");
        }


        return Result.error("更新失败");
    }
}




